﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Project.Web.Base;

using CNDreams.Entity;
using CNDreams.Enum;
using CNDreams.Web.Base;
using Project.Common;
using Project.Entity.Base;
using Project.Web.Base.Utility;
using CNDreams.ServiceInterface;
using Serialize.Linq.Extensions;

namespace CNDreams.Web.Areas.ModuleSys.Models
{
	public class ModelPasswordRetrieve
	{
	}

	public class ModelPasswordRetrieveIndex : BaseModel
	{
		private IServiceSysUser bizSysUser;
		private IServiceUTOrgDepartment bizUTOrgDepartment;
		private BaseSearch searchEntity;
		public BaseSearch SearchEntity
		{
			get
			{
				if (searchEntity == null)
					return new BaseSearch();
				return searchEntity;
			}
			set { searchEntity = value; }
		}

		/// <summary>
		/// 根据组织机构ID得到部门
		/// </summary>
		public IList<UTOrgDepartment> UTOrgDepartmentCollection { get; set; }

		public IList<SysUser> SysUserCollection { get; set; }
		public IList<SysUser> SysUser { get; set; }

		public IList<SysUser> GridDataSources { get; set; }

		public void RetriveData()
		{
			ExpressionCondition<SysUser> condition = ExpressionCondition<SysUser>.GetInstance();
			condition.And(x => x.UserType == (int)EnumInternalUserType.多方登录账号);
			if (!string.IsNullOrEmpty(SearchEntity._CommonSearchCondition))
				condition.Or(x => x.UserName, SearchEntity._CommonSearchCondition, ExpressionValueRelation.Like).
					Or(x => x.Email, SearchEntity._CommonSearchCondition, ExpressionValueRelation.Like);

			GridDataSources = bizSysUser.PaginateListBy(SearchEntity._PageSize.Value, SearchEntity._PageIndex ?? 0, ref Count, condition.ConditionExpression.ToExpressionNode(), SearchEntity._OrderName, SearchEntity.EnumOrderDirection);
			PaginateHelperObject = PaginateHelper.ConstructPaginate(SearchEntity._PageSize.Value, Count, SearchEntity._PageIndex ?? 0, SearchEntity, "SearchEntity",HttpContext.Current.Request.RawUrl);
		}
	}
}